package com.ruoyi.goodsInfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.goodsInfo.vo.GoodsAddVo;
import com.ruoyi.goodsInfo.vo.GoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goodsInfo.domain.Goods;
import com.ruoyi.goodsInfo.service.GoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * goodsInfoController
 *
 * @author ruoyi
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/goodsInfo/goodsInfo")
@Api("商品信息管理")
public class GoodsController extends BaseController
{
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询goodsInfo列表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(String goodsName,String priceLevel)
    {
        startPage();
        List<GoodsVo> list = goodsService.searchGoodsList(goodsName,priceLevel);
        return getDataTable(list);
    }

    /**
     * 导出goodsInfo列表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:export')")
    @Log(title = "goodsInfo", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Goods goods)
    {
        List<Goods> list = goodsService.selectGoodsList(goods);
        ExcelUtil<Goods> util = new ExcelUtil<Goods>(Goods.class);
        util.exportExcel(response, list, "goodsInfo数据");
    }

    /**
     * 获取goodsInfo详细信息
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsService.selectGoodsById(id));
    }

    /**
     * 新增goodsInfo
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:add')")
    @Log(title = "goodsInfo", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增商品")
    public AjaxResult add(@RequestBody GoodsAddVo goodsAddVo)
    {
        return toAjax(goodsService.insertGoods(goodsAddVo));
    }

    /**
     * 修改goodsInfo
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:edit')")
    @Log(title = "goodsInfo", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsAddVo goodsAddVo)
    {
        return toAjax(goodsService.updateGoods(goodsAddVo));
    }

    /**
     * 删除goodsInfo
     */
    @PreAuthorize("@ss.hasPermi('goodsInfo:goodsInfo:remove')")
    @Log(title = "goodsInfo", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsService.deleteGoodsByIds(ids));
    }
}
